<?php

class PublicAction extends Action{
	
	public function index(){
		$this->redirect('Public/login');
	}

	public function login(){
		if(!isset($_REQUEST['name'])){
			$this->display();
			die();
		}
		$name = $_REQUEST['name'];
		$password = $_REQUEST['password'];
		if($name == ''||password==''){
			echo 'error param';
			return;
		}
		 
		$model = M('Admin');
		$where['name'] = $name;
		$where['password'] = md5($password);
		$where['status'] = 1;
		$res = $model ->where($where)->find();
		 
		if(!$res){
			echo 'error user';
			return;
		}
	
		//authen menus
		$Menu = D('Menu');
		$menus = $Menu->getByRoleid($res['roleid']);
		$userUrls = array();
		foreach($menus as $m){
			$userUrls[] = $m['url']; 
		}
		$_SESSION['menus'] = $menus;
		$_SESSION['userUrls'] = $userUrls;
		$_SESSION['user']  = $res['name'];
 		$this->redirect("Index/index");
	}
	public function logout(){
		session_destroy();
		$this->success('logout success','__GROUP__/Public/login');
	}
	
}

?>